package EX1;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class demo9 {
    public static void main(String[] args) throws SQLException {
        MysqlDataSource ds=new MysqlDataSource();
        ds.setUrl("jdbc:mysql://localhost:3306/yonghu?useSSL=false");
        ds.setUser("root");
        ds.setPassword("123456");
        Connection conn= ds.getConnection();
        String updatesql="update student set name=? where id=?";


        Scanner sc=new Scanner(System.in);
        System.out.println("输入您要修改名字的同学的学号");
        int a=sc.nextInt();
        System.out.println("请输入要修改的名字");
        String b= sc.next();

        PreparedStatement ps= conn.prepareStatement(updatesql);
        ps.setInt(2,a);
        ps.setString(1,b);
        int n=ps.executeUpdate();
        System.out.println("这条sql语句影响到"+n+"条记录");

        ps.close();
        conn.close();
    }
}
